package cn.zswltech.gruul.web.api.controller;

import cn.zswltech.gruul.api.FunctionApi;
import cn.zswltech.gruul.biz.service.FunctionService;
import cn.zswltech.gruul.common.dto.*;
import cn.zswltech.gruul.common.result.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Jim
 * @version 1.0.0
 * @descripition:
 * @date 2024/3/1 0:57
 */
@RestController
@Slf4j
public class FunctionController implements FunctionApi {

    @Autowired
    private FunctionService functionService;

    @Override
    public Response<List<FunctionInfo>> underMenuFunctionList(UnderMenuFunctionListREQ req) {
        try {
            return Response.success(functionService.underMenuFunctionList(req));
        } catch (Exception e) {
            log.error("获取菜单下功能列表失败 req:{}",req,e);
            return Response.error(500,"获取菜单下功能列表失败");
        }
    }

    @Override
    public Response underMneuFunctionAdd(UnderMenuFunctionAddREQ req) {
        try {
            functionService.underMneuFunctionAdd(req);
        } catch (Exception e) {
            log.error("菜单下功能接口新增失败 req:{}",req,e);
            return Response.error(500, "菜单下功能接口新增失败");
        }
        return Response.success();
    }


    @Override
    public Response underMenuFunctionUpdate(UnderMenuFunctionUpdateREQ req) {
        try {
            functionService.underMenuFunctionUpdate(req);
        } catch (Exception e) {
            log.error("菜单下功能接口修改失败 req:{}", req,e);
            return Response.error(500, "菜单下功能接口修改失败");
        }
        return Response.success();
    }

    @Override
    public Response underMenuFunctionDel(UnderMenuFunctionDelREQ req) {
        try {
            functionService.underMenuFunctionDel(req);
        } catch (Exception e) {
           log.error("菜单下功能接口删除失败 req:{}", req,e);
           return Response.error(500, "菜单下功能接口删除失败");
        }
        return Response.success();
    }


}
